import json

'''写文件'''
# numbers = [2,3,5,7,11,13]
# file_name = 'number.json'
# with open(file_name,'w') as f:
#     json.dump(numbers,f)


'''读文件'''
# filename = 'number.json'
# with open(filename) as f:
#     nus = json.load(f)
#
# print(nus)




'''
如果以前储存了用户名就加载。
否则就提示用户输入用户名，并储存它。
'''
filename = 'username.json'
try:
    with open(filename) as f:
        username = json.load(f)
except Exception:
    username = input('What is you name?')
    with open(filename, 'a') as f:
        json.dump(username, f)
        print(f"We will remember you when you come back,{username.title()}!")
else:   # try执行成功后执行的代码块
    print(f"Welcome back,{username.title()}!")


